package com.phone580.app;

import com.phone580.app.untilty.AlertUtil;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

abstract public class BaseTask extends AsyncTask<Void, Integer, Object> {
	//执行成功回调接口
	private TaskCallback callback;
	private ProgressDialog dialog;
	protected Context context;
	
	public BaseTask(Context context) {
		this.context = context;
	}
	
	public void setTaskCallback(TaskCallback callback) {
		this.callback = callback;
	}
	
	abstract public void setParams(Object ...params);
	
	protected void showDialog(String tips, boolean isCancel) {
		dialog = AlertUtil.showProgress(context, tips);
		dialog.setCancelable(isCancel);
		dialog.show();
	}
	
	protected void dismissDialog() {
		if (dialog != null && dialog.isShowing()) {
			dialog.dismiss();
		}
	}
	
	@Override
	protected void onPostExecute(Object result) {
		dismissDialog();
		if (callback != null) {
			callback.execute(result);
		}
	}
	
	//回调接口定义
	public interface TaskCallback {
		void execute(Object result);
	}

}
